<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜房订单录入页面')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <!--菜房1-->
                        <!--<input type="hidden" name="cforderFor" value="1"/>-->
                        <input type="hidden" name="status" th:value="${status}"/>


                        <li>
                            订单类型：<select name="cforderType" th:with="type=${@dict.getType('cforderType')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            作物名称：<input type="text" name="cropNameCn"/>
                        </li>

                        <li>
                            作物品种：<input type="text" name="cropVarietiesCn"/>
                        </li>

                        <li class="select-time">
                            <label>需求时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>

                        <li>
                            状态：<select name="cforderStatus" th:with="type=${@dict.getType('cforderStatus')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncOrderCf:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:ncOrderCf:edit">
                <i class="fa fa-edit"></i> 修改
            </a>-->
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="system:user:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:ncOrderCf:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 确认
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncOrderCf:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncOrderCf:remove')}]];
    var prefix = ctx + "system/ncOrderCf";
    var datas = [[${@dict.getType('cforderType')}]];
    var cforderStatus = [[${@dict.getType('cforderStatus')}]];
    var normal_unit = [[${@dict.getType('normal_unit')}]];
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "菜房订单",
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'cforderId',
                    title: '订单号',
                    sortable: false
                },
                {
                    field: 'cforderCode',
                    title: '订单编号',
                    sortable: true
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                    sortable: true
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                    sortable: true
                },
                {
                    field: 'requestTime',
                    title: '需求日期',
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    }
                },
                {
                    field: 'cforderId',
                    title: '菜房订单键',
                    visible: false
                },
                {
                    field: 'cforderType',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },

                {
                    field: 'requestAmount',
                    title: '需求数量',
                    sortable: true
                },
                {
                    field: 'unit',
                    title: '单位',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(normal_unit, value);
                    }
                },
                {
                    field: 'hasPlan',
                    title: '匹配计划',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if ('1' == value) {
                            return row.planCode
                        }
                        if ('2' == value) {
                            return "未匹配"
                        }
                        return "--";
                    }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editOrderPlan(\'' + row.cforderId + '\')"><i class="fa fa-warning"></i>匹配计划</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.cforderId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.cforderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*表单确认*/
    function confirmTable() {
        var confirmTable = prefix + "/confirmTable";
        var data = $('#bootstrap-table').bootstrapTable('getData');
        if (data && data.length > 0) {

            $.modal.confirm("确认生成订单记录单吗？", function () {
                var ids = [];
                $(data).each(function (i, e) {
                    ids.push(e.cforderId);
                });
                var ids_str = ids.join(",");
                myPost(confirmTable, {ids: ids_str},
                    function (data) {
                        if (data.code == 0) {
                            layer.msg("提交成功")
                        } else {
                            layer.msg(data.msg);
                        }
                        $.table.refresh()
                    }, function (e) {
                        layer.msg("确认失败!");
                        $.table.refresh()
                    })

            })
        } else {
            layer.msg("未发现数据!")
        }

    }

    function editOrderPlan(cforderId) {
        var url = ctx + 'system/ncOrderCf/editOrderPlan/' + cforderId
        $.modal.open("匹配计划", url);
    }
    setTitle("订单录入",true)
</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
               <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs">
                   <i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>